package com.code.feign.controller;

import com.code.feign.feign.ProduceApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author liyufei
 * @since 2018-12-07 22:14
 */
@RestController
public class ConsumerController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private ProduceApi api;

    @GetMapping("/consumer")
    public String consumer(@RequestParam("name") String name) {
        return api.index(name, port);
        // return "参数值为：" + name;
    }

    @GetMapping("/get")
    public String get() {
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:8080/config-get", String.class);
        return responseEntity.getBody();
    }
}
